package com.my.controller;

import com.my.entity.Emp;
import com.my.entity.LoginInfo;
import com.my.entity.Result;
import com.my.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
public class LoginController {

    @Autowired
    private EmpService empService;

    @PostMapping("/login")
    public Result login(@RequestBody Emp emp){
        log.info("员工来了~~{}",emp);
        log.info("当前线程{}",Thread.currentThread().getName());
        LoginInfo loginInfo = empService.login(emp);

        // 如果为空不允许登录
        if(loginInfo == null){
            log.info("用户名或密码错误");
            return Result.error("用户名或密码错误！！");
        }

        return Result.success(loginInfo);
    }
}
